The CtlHTMLPartialOwnerDraw function provides the ability to change the way command buttons, check boxes, and radio button controls are displayed.
typedef BOOL (*PFNPartialOwnerDraw)(
HWND hWnd, // handle to the control
HDC hDC, // handle to the control device context
LPSTR szText, // pointer to the control text
RECT * pClientRect, // pointer to the control client rectangle
RECT * pTextRect, // pointer to the text rectangle
int textStyle, // the text style
BOOL isPushButton, // if TRUE, control is a push button
BOOL hasFocus, // if TRUE, control has focus
BOOL isDown, // if TRUE, control push button is down
BOOL calcSize // if TRUE, the control size is being calculated
);
void CtlHTMLPartialOwnerDraw(
PFNPartialOwnerDraw partialOwnerDraw // pointer to the ownerdraw callback function
);
The callback function returns TRUE if the text is to be drawn, otherwise it returns FALSE.
Call the CtlHTMLPartialOwnerDraw function to set a callback function to change the way command buttons, check boxes, and radio button controls are displayed. A single callback function is used for all controls, so you need to determine the controls you wish to ownerdraw from the input parameters, typically by using GetDlgCtrlID API function. For example with MFC:
// Draws radio buttons using colors instead of text. The control text contains the RGB color value.
BOOL MyPartialOwnerDraw (HWND hWnd, HDC hDC, LPSTR szText, RECT *pClientRect, RECT *pTextRect,
int textStyle, BOOL isPushButton, BOOL hasFocus, BOOL isDown, BOOL calcSize)
{
int id;
id = GetDlgCtrlID(hWnd);
if (id == IDC_OWNERDRAWRB1 || id == IDC_OWNERDRAWRB2 || id == IDC_OWNERDRAWRB3)
{
// in this case, the ownerdraw doesn't change the size
if (calcSize)
return TRUE;
COLORREF color;
HBRUSH hBrush, hOldBrush;
HPEN hPen, hOldPen;
// set the brush and pen
if (IsWindowEnabled(hWnd))
{
sscanf(szText, "%x", &color);
hBrush = CreateSolidBrush(color);
}
else
hBrush = GetSysColorBrush(COLOR_GRAYTEXT); // use same color as disabled text
hPen = (HPEN)GetStockObject(BLACK_PEN);
hOldBrush = (HBRUSH)SelectObject(hDC, hBrush);
hOldPen = (HPEN)SelectObject(hDC, hPen);
// do drawing
if (isPushButton)
{
if (isDown)
Rectangle(hDC, pTextRect->left + 5, pTextRect->top + 5, pTextRect->right - 3, pTextRect->bottom - 3);
else
Rectangle(hDC, pTextRect->left + 4, pTextRect->top + 4, pTextRect->right - 4, pTextRect->bottom - 4);
}
else
Rectangle(hDC, pTextRect->left, pTextRect->top, pTextRect->right, pTextRect->bottom);
// be sure to restore all GDI objects
SelectObject(hDC, hOldBrush);
SelectObject(hDC, hOldPen);
// draw the focus rect
if (hasFocus)
{
RECT focusRect;
focusRect = *pTextRect;
InflateRect(&focusRect, -2, -2);
DrawFocusRect(hDC, &focusRect);
}
// return TRUE to not draw the text
return TRUE;
}
else
return FALSE;
}
You can use partial ownerdraw to change practically any attribute of the control's appearance, such as the control size and text attributes (such as the text color and background color), as well as drawing icons or bitmaps to the control.
Copyright ⌐ 1999, Windmill Point Software. All Rights Reserved.
Last Updated May 19, 1999